/**
 * @desc 证书管理
 * @author yd_zhaorongjun
 */
<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <!-- 按状态 -->
        <el-col :md="6" :lg="4">
          <p>{{ $t('search.state') }}</p>
          <el-select v-model="CertificateQO.state" size="mini" :placeholder="$t('search.placeholder_State')" filterable @change="refreshList">
            <!-- <el-option v-for="item in items" :key="item" :label="item" :value="item" /> -->
          </el-select>
        </el-col>
        <!-- 名称 -->
        <el-col :md="6" :lg="4">
          <p>{{ $t('search.name') }}</p>
          <el-input v-model="CertificateQO.name" :placeholder="$t('search.placeholder_Name')" size="mini" clearable @change="refreshList" />
        </el-col>
        <el-col :md="6" :lg="4">
          <!-- 查询按钮 -->
          <el-button style="margin-top:27px" type="primary" size="mini" @click="refreshList">{{ $t('button.query') }}</el-button>
          <!-- 重置按钮 -->
          <el-button style="margin-top:27px" type="warning" size="mini" @click="refreshSearchForm">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <template>
      <el-row :gutter="20" class="gl_my_15">
        <!-- 添加证书按钮 -->
        <el-col :md="6" :lg="4">
          <el-button type="primary" size="mini" @click="editOfAdd()">{{ $t('button.addCertificate') }}</el-button>
        </el-col>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        stripe
        size="mini"
        style="width: 100%;"
      >
        <!-- 证书名称 -->
        <el-table-column
          prop="certificateName"
          :label="$t('table.certificateName')"
          width="180"
        />
        <!-- 创建日期 -->
        <el-table-column
          prop="starTime"
          :label="$t('table.creationTime')"
          align="center"
          width="160"
        />
        <!-- 状态 -->
        <el-table-column
          :label="$t('table.status')"
          align="center"
          width="100"
        >
          <template slot-scope="{row}">
            <span v-if="row.stateType" class="gl_color_success">{{ $t('table.isApproval') }}</span>
            <span v-else>{{ $t('table.noApproval') }}</span>
          </template>
        </el-table-column>
        <!-- 描述 -->
        <el-table-column
          prop="description"
          :label="$t('table.description')"
          min-width="240"
        />
        <!-- 操作 -->
        <el-table-column fixed="right" :label="$t('table.actions')" width="180">
          <template slot-scope="{row,$index}">
            <!-- 编辑按钮 -->
            <el-button size="mini" type="text" @click="editOfAdd(row,$index)">
              {{ $t('table.edit') }}
            </el-button>
            <!-- 审批按钮 -->
            <el-button v-if="!row.stateType" size="mini" type="text" @click="clickApproval(row)">
              {{ $t('table.examine') }}
            </el-button>
            <!-- 删除按钮 -->
            <el-button v-if="!row.stateType" size="mini" type="text" @click="clickDelete(row)">
              {{ $t('table.delete') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-row class="gl_pt_20" style="text-align: center;">
        <el-pagination
          :current-page="currentPage"
          :page-size="CertificateQO.MaxResultCount"
          :total="totalPage"
          layout="total,sizes,prev,pager,next,jumper"
          :page-sizes="[10, 20, 30, 40]"
          @size-change="sizeChange"
          @current-change="pageIndexChange"
        />
      </el-row>
    </template>

    <edit-certificate ref="editCertificate" @insert="certificateInsert" @update="certificateUpdate" />
  </div>
</template>

<script>

import { CertificateQO } from '@/lib/form/grade.js';
import { translateByCode } from '@/lib/getTransData';
import editCertificate from './editCertificate';
export default {
  name: 'Certificate',
  components: {
    editCertificate
  },
  data() {
    return {
      CertificateQO: new CertificateQO(),
      loading: false,
      currentPage: 1,
      totalPage: 0,
      tableData: [{
        certificateName: '证书名称',
        phone: '13911387623',
        address: '湖北省武汉市江汉区',
        orgType: '专业版',
        starTime: '2018-04-22 09:23:23',
        endTime: '2018-04-22 09:23:23',
        creator: '张颖',
        stateType: true,
        description: '详细描述事情的经过的经过的经过的经过'
      }, {
        certificateName: '证书名称证书名称',
        phone: '13911387623',
        address: '湖北省武汉市凤凰区',
        orgType: '专业版',
        starTime: '2018-04-22 09:23:23',
        endTime: '2018-04-22 09:23:23',
        creator: '爱诗诗',
        stateType: false,
        description: '详细描述事情的经过的经过的经过的经过'
      }, {
        certificateName: '证书名称证书名称',
        phone: '13911387623',
        address: '湖北省武汉市江汉区',
        orgType: '专业版',
        starTime: '2018-04-22 09:23:23',
        endTime: '2018-04-22 09:23:23',
        creator: '爱谁谁',
        stateType: false,
        description: '详细描述事情的经过的经过的经过的经过'
      }, {
        certificateName: '证书名称',
        phone: '13911387623',
        address: '湖北省武汉市江汉区',
        orgType: '专业版',
        starTime: '2018-04-22 09:23:23',
        endTime: '2018-04-22 09:23:23',
        creator: '小肥',
        stateType: true,
        description: '详细描述事情的经过的经过的经过的经过'
      }]
    };
  },
  computed: {
  },
  created() {
    this.refreshList();
  },
  methods: {
    // 刷新列表
    refreshList() {
      // TODO
    },
    // 重置搜索表单
    refreshSearchForm() {
      this.CertificateQO = new CertificateQO();
      this.freeDay = [];
    },
    // 日历选择器给QO赋值
    timeChange(val) {
      this.CertificateQO.starTime = this.freeDay[0];
      this.CertificateQO.endTime = this.freeDay[1];
      console.log(this.CertificateQO);
    },
    // 添加或修改用户
    editOfAdd(row) {
      this.$refs.editCertificate.open(row);
    },
    // 删除按钮
    clickDelete(row) {
      // TODO
      // 您确定要删除 xxx 吗？ zh
      const _confirmStr = ` ${translateByCode('alert.wantDelete')} [ ${row.certificateName} ] ${translateByCode('alert.ma')}`;
      this.$confirm(_confirmStr, translateByCode('alert.warning'), {
        confirmButtonText: translateByCode('alert.confirm'),
        cancelButtonText: translateByCode('alert.cancel'),
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          // 删除成功！
          message: translateByCode('alert.deleteSuccessfully')
        });
        this.refreshList();
      }).catch(() => {
      });
    },
    // 添加用户
    certificateInsert(vo) {
      // TODO
      this.$message({
        // 添加成功！
        message: translateByCode('alert.addSuccessfully'),
        type: 'success'
      });
      this.$refs.editCertificate.close();
      this.refreshList();
    },
    // 修改用户
    certificateUpdate(vo) {
      // TODO
      this.$message({
        // 修改成功！
        message: translateByCode('alert.editSuccessfully'),
        type: 'success'
      });
      this.$refs.editCertificate.close();
      this.refreshList();
    },
    sizeChange: function(MaxResultCount) {
      this.CertificateQO.MaxResultCount = MaxResultCount;
      this.refreshList();
    },
    pageIndexChange(currentPage) {
      this.currentPage = currentPage;
      this.CertificateQO.SkipCount = (currentPage - 1) * this.CertificateQO.MaxResultCount;
      this.refreshList();
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
